package com.example.admin.yuejian_22.Model;



import com.example.admin.yuejian_22.Bean.AppIntroBean;
import com.example.admin.yuejian_22.Bean.ClubFavorBean;
import com.example.admin.yuejian_22.Bean.ClubList;
import com.example.admin.yuejian_22.Bean.CommentBean;
import com.example.admin.yuejian_22.Bean.FanUser;
import com.example.admin.yuejian_22.Bean.MyPhotoBean;
import com.example.admin.yuejian_22.Bean.OrderBean;
import com.example.admin.yuejian_22.Bean.PhotoBean;
import com.example.admin.yuejian_22.Bean.SendCBean;
import com.example.admin.yuejian_22.Bean.UserBean;
import com.example.admin.yuejian_22.Interf.RetrofitService;
import com.example.admin.yuejian_22.Interf.UserInterf;
import com.example.admin.yuejian_22.Listener.UserListener;

import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserModel implements UserInterf{
    private RetrofitService retrofitService;
  //private static final String BASE_URL = "http://172.24.10.175/workout/api.php/";
private static final String BASE_URL = "http://dhp30778.51vip.biz/workout/api.php/";
    private Retrofit retrofit;
    public UserModel() {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }

    private void SetCallBack(Call call,final UserListener userListener){
        call.enqueue(new Callback() {
            @Override
            public void onResponse(Call call, Response response) {
                if (response.isSuccessful() && response.body() != null) {
                    userListener.onResponse(response.body());
                } else {
                    userListener.onFail("123");
                }
            }
            @Override
            public void onFailure(Call call, Throwable t) {
                userListener.onFail("343453453");
                userListener.onFail(t.toString());
            }
        });
    }
//登录
    @Override
    public void Login(String tel, String password,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<UserBean> call =retrofitService.Login(tel,password);
        call.enqueue(new Callback<UserBean>() {
            @Override
            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
                if (response.isSuccessful()&&response.body().getError()==null)
                    userListener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                userListener.onFail("登录失败!");
            }
        });
    }


    //注册
    @Override
    public void getRegister(String tel, String password, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
       Call<UserBean> call = retrofitService.getRegister(tel,password);
        SetCallBack(call,userListener);
    }
//获取id
    @Override
    public void getUserByID(String id,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<UserBean> call =retrofitService.getUserById("nvce90j6lk2cuorca7k6vl68g4","user",id);
        SetCallBack(call,userListener);
    }

//俱乐部最具人气
    @Override
    public void getAllClub(final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<ClubList>> call =retrofitService.getAllClub();
        SetCallBack(call,userListener);
    }
//俱乐部离我最近
    @Override
    public void getNearClub(final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<ClubList>> call =retrofitService.getNearClub();
        SetCallBack(call,userListener);
    }

    //俱乐部搜索
    @Override
    public void getSearchClub(String club_name, final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<ClubList>> call = retrofitService.getSearchClub(club_name);
        SetCallBack(call,userListener);
    }
//俱乐部课程
    @Override
    public void getCourseinfo(String id,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<ClubList> call = retrofitService.getCourseinfo("lgj98rfkiqvenhrk2o7oe2po81","1","Clubcourse","club",id);
        SetCallBack(call,userListener);

    }

    //俱乐部视频
    @Override
    public void getVideoinfo(String id, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<ClubList> call = retrofitService.getVideoinfo("lgj98rfkiqvenhrk2o7oe2po81","1","Clubvideo","club",id);
        SetCallBack(call,userListener);

    }

    //个人中心个人信息
    @Override
    public void getUserInfo(String SessionID, String userid,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<UserBean> call = retrofitService.getUserInfo("lgj98rfkiqvenhrk2o7oe2po81",userid);
        SetCallBack(call,userListener);

    }
    //个人中心关于约健
    @Override
    public void getAppIntro(String SessionId,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<AppIntroBean> call = retrofitService.getAppIntro("060pn7sjorpnq5fp53kid5st54");
        SetCallBack(call,userListener);
    }
//个人中心：晒图列表
    @Override
    public void getMyPhoto(String userid, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<MyPhotoBean>> call = retrofitService.getMyPhoto(userid);
        SetCallBack(call,userListener);
    }
//个人中心：关注俱乐部
    @Override
    public void getclubgz(String userid,String fan_id, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<ClubFavorBean>> call = retrofitService.getclubgz(userid,fan_id);
        SetCallBack(call,userListener);

    }
    //个人中心所有订单
    @Override
    public void getAllOrder(String userid, String vstate, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<OrderBean>> call = retrofitService.getAllOrder(userid,vstate);
        SetCallBack(call,userListener);


    }

    //    @Override
//    public void getInfo(String SessionID, String userid,final UserListener userListener) {
//        retrofitService = retrofit.create(RetrofitService.class);
//        Call<List<UserBean>> call = retrofitService.getInfo("lgj98rfkiqvenhrk2o7oe2po81",userid);
//        SetCallBack(call,userListener);
//
//    }



    //个人中心帮助与反馈
    @Override
    public void sendHelp(String content, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<Integer> call = retrofitService.sendHelp(content);
        SetCallBack(call,userListener);

    }

    @Override
    public void getEdituname(String user_name, String userid, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<UserBean> call = retrofitService.getEdituname(user_name,userid);
        SetCallBack(call,userListener);

    }

    @Override
    public void getEditpassword(String password ,String userid ,UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<UserBean> call = retrofitService.getEditpassword(password,userid);
        SetCallBack(call,userListener);

    }

    //晒图列表
    @Override
    public void getPhotolist(UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<PhotoBean>> call = retrofitService.getPhotolist();
        SetCallBack(call,userListener);

    }
    //评论列表
    @Override
    public void getCommentlist(UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<List<CommentBean>> call = retrofitService.getCommentlist();
        SetCallBack(call,userListener);

    }
    //回复评论
    @Override
    public void sendComment(String reply, String shaitu_id, String userid, String reply_userid,final UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<Integer> call = retrofitService.sendComment(reply,shaitu_id,userid,reply_userid);
        SetCallBack(call,userListener);
    }
    //判断是否关注俱乐部
    @Override
    public void ifgz(String fan_id, String userid, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<Integer> call = retrofitService.ifgz(fan_id,userid);
        SetCallBack(call,userListener);
    }
    //关注俱乐部
    @Override
    public void clubfan(String userid, String fan_id, UserListener userListener) {
        retrofitService = retrofit.create(RetrofitService.class);
        Call<Integer> call = retrofitService.clubfan(userid,fan_id);
        SetCallBack(call,userListener);

    }



//    public void getClubcourse(String id, final UserListener userListener) {
//        retrofitService = retrofit.create(RetrofitService.class);
//        Call<ClubcourseList> call = retrofitService.getClubcourse("1", id, "Clubcourse");
//        SetCallBack(call,userListener);
//    }




}


